package com.lxs.mall.util;

import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.geometry.Positions;

import java.io.IOException;

/**
 * @author 小松
 */
public class ImageUtil {
    public static void main(String[] args) throws IOException {
        String path = "/E:/data_storage/";
        //切割
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .sourceRegion(Positions.BOTTOM_RIGHT,800,800).size(1000,1000)
                .toFile(path+"00000.jpg");
        //按比例缩放
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .scale(0.5).toFile(path+"00000.jpg");
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .scale(1.5).toFile(path+"000001.jpg");
        //按长宽缩放  keepAspectRatio(false/true)是否按比例缩放
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .size(500,500).keepAspectRatio(false).toFile(path+"000002.jpg");
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .size(500,500).keepAspectRatio(true).toFile(path+"000003.jpg");
        //旋转90
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .size(500,500).keepAspectRatio(true).rotate(90).toFile(path+"0000001.jpg");
        //旋转180
        Thumbnails.of(path+"973d2e4a-e7df-4d5b-b84d-d610e8a5b9a0.jpg")
                .size(500,500).keepAspectRatio(true).rotate(180).toFile(path+"0000002.jpg");
    }
}
